Z.compress = a => {
	let c = [a[0] ? 199 : 1]
	for(let i=1; i<a.length; i++)
		if(a[i] == a[i-1])
			++c[c.length-1]
		else
			c.push(a[i] ? 199 : 1)
	return c
}
Z.uncompress = a => {
	let c = []
	for(let i=0; i<a.length; i++){
		let t = 0
		if(a[i] > 198){
			a[i] -= 198
			t = 1
		}
		for(let j=0; j<a[i]; j++)
			c.push(t)
	}
	return c
}
Z.c = [[3,199,4,199,1,199,1,199,3,199,3,199,5,201,1,204,1,204,1,204,1,201,1,202,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,4,203,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,1,199,6,199,6,199,6,199,12,200,2],[3,199,5,200,1,200,2,200,2,200,4,201,1,204,1,204,1,204,1,201,1,202,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,4,203,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,1,199,6,199,6,199,6,199,12,200,2],[4,199,5,199,1,199,3,199,3,199,3,203,1,204,1,204,1,204,1,201,2,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,203,4,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,1,199,7,199,6,199,6,199,11,200,2],[201,2,199,2,199,2,199,3,199,3,199,3,199,1,202,1,204,1,204,1,204,1,201,2,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,203,4,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,1,199,8,199,6,199,4,200,11,199,1,199,1],[199,4,199,3,199,1,200,3,199,3,199,4,202,1,204,1,204,1,204,1,201,2,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,203,4,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,1,199,8,199,24,199,1,199,1],[1,199,3,199,5,200,3,199,3,199,3,203,1,204,1,204,1,204,1,201,2,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,203,4,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,1,199,15,199,17,199,1,199,1],[2,199,2,199,2,199,1,199,1,199,3,199,3,199,4,202,1,204,1,204,1,204,1,201,2,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,203,4,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,1,199,20,200,11,200,2],[5,200,2,200,1,199,3,199,3,199,12,201,1,204,1,204,1,202,8,201,1,204,1,204,1,204,1,204,1,204,1,201,9,200,2,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,1,199,3,199,29,200,2],[7,199,2,199,1,199,3,199,3,199,3,199,1,201,1,204,1,204,1,204,1,202,1,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,2,200,2,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,1,199,10,199,22,200,2],[26,201,3,201,1,200,2,200,1,201,1,202,2,199,2,201,1,204,1,204,1,204,1,201,129],[57,202,1,200,1,206,1,200,1,202,2,199,1,202,1,203,2,199,1,203,109]].map(a=>Z.uncompress(a))
Z.e = [[2,199,2,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,2,201,7,200,1,199,5,199,5,199,3],[2,199,2,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,2,202,4,199,1,202,5,199,5,199,3],[199,2,203,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,4,199,7,200,2,199,5,199,5,199,2],[199,2,203,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,4,199,7,200,9,199,7],[199,2,203,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,4,199,7,200,3,199,13],[199,2,203,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,4,199,7,200,1,200,4,200,4,200,2],[1,199,10,201,1,204,1,204,1,204,1,204,1,204,1,201,14,201,1,204,1,204,1,203,2,199,7,200,15,199,1],[1,199,3,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,203,2,199,7,200,16,199],[5,202,2,200,1,200,1,200,1,202,1,199,7,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,1,199,6,199,14,200,6],[5,202,2,200,1,200,1,200,14,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,1,199,6,199,14,200,6],[5,202,2,199,2,203,1,202,1,199,7,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,1,199,6,199,8,200,12],[5,202,2,199,2,203,14,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,1,199,6,199,8,200,12],[5,201,1,204,1,204,1,204,1,204,1,204,1,204,1,204,1,201,34,200,23],[5,201,3,201,1,200,2,200,1,201,1,202,2,202,1,204,1,204,1,204,1,201,59],[33,202,2,202,1,200,1,199,1,203,1,202,1,199,8,203,1,202,2,199,1,202,1,199,31]].map(a=>Z.uncompress(a))

Z.coded = [0, 0x77, 0x06, 0x6b, 0x2f, 0x1e, 0x3d, 0x7d, 0x07, 0x7f, 0x3f,	//'' 0-9 0-10
			0x71, 0x6c, 0x6e, 0x79,	 //CodE 11-14
			0x51, 0x4c, 0x5b, 0x70, 0x48, 0x76, 0x5f, 0x7c, 8	//T, n, P, L r U A b -  15-23
]
Z.menu = [
	[0, 6, 14, 15],		//set
	[2, 16, 17, 15],	//inpt
	[11, 12, 16, 16],	//conn
	[13, 12, 23, 2],	//do-1
	[],

	[11, 12, 13, 14],	//code 5
	[13, 2, 6, 17],		//disp
	[11, 18, 19, 14],	//clre
	[0, 13, 2, 6],		//dis
	[0, 13, 14, 18],	//del  

	[0, 16, 14, 15],	//net 10
	[20, 6, 11, 18],	//uscl
	[2, 6, 11, 18],		//iscl
	[0, 0, 17, 15],		//pt
	[0, 0, 11, 15],		//ct  

	[0, 0, 6, 16],		//sn  15
	[22, 21, 20, 13],	//baud
	[13, 21, 15, 21],	//data
	[],[],

	[13, 20, 21, 0], 	//dua 20
	[13, 20, 22, 0], 	//dua
]
Z.lcd = {
	svg: [],
	all: Z.c,
	dis: Z.c[0],
	page: 0,
	brightness: 0,	//0.05
	num: [27,34,41,48,57,64,71,78,106,99,92,85]
}
Z.led = {
	svg: [],
	all: Z.e,
	dis: Z.e[0],
	page: 0,
	brightness: 0,	//0.2
	num: [6,13,20,27,55,48,41,34,62,69,76,83]
}

Z.dis = (() => {
	let p = 0, c, d, n, x, b
	let flash = (()=>{
		let interval = 0
		let iFlash = 0
		return (i=0) => {
			if(interval){
				clearInterval(interval)
				interval = 0
				for(let i=0; i<7; i++)
					if(x.dis[i+iFlash-1])
						x.svg[i+iFlash].style.opacity = 1
			}
			if(i){
				let tag = true
				iFlash = x.num[i-1]

				interval = setInterval(() => {
					for(let i=iFlash; i<7+iFlash; i++)
						x.svg[i].style.opacity = (tag & x.dis[i-1]) ? 1 : x.brightness
					tag = !tag						
				}, 400)

				setTimeout(() => {
					for(let i=iFlash; i<7+iFlash; i++)
						x.svg[i].style.opacity = x.brightness
				}, 3)	//code flaw, because of watch's mechanism, this section is not necessary
			}
		}		
	})()
	let set = (w, n) => {for(let i=0; i<7; i++) x.dis[x.num[w-1] - 1 + i] = (Z.coded[n] >> 6 - i) & 1}
	let f = [
		()=>{		//0 page
			x.page += b-1 ? 1 : -1
			if(x.page > x.all.length - 3)
				x.page = 0
			else if(x.page < 0)
				x.page = x.all.length - 3
			x.dis = x.all[x.page]
		},
		()=>{		//1 code
			if(b==1){
				if(c-- == 5) c = 8
				flash(c)
			}else{
				if(n[c-5]++ == 9) n[c-5] = 0
				set(c, n[c-5]+1)
			}
		},
		()=>{		//2 menu level 1
			c += b-1 ? 1 : -1
			if(c == 4) c = 0
			else if(c == -1) c = 3
			Z.menu[c].map((i, j) => set(j+1, i))
		},
		()=>{		//3 menu level 2
			let t = [[5, 9], [10, 14], [15, 17], [20, 21]]
			d += b-1 ? 1 : -1
			if(d == t[c][0]-1) d = t[c][1]
			else if(d == t[c][1]+1) d = t[c][0]
			Z.menu[d].map((i, j) => set(j+5, i))			
		},
		()=>{		//4 menu level 3

		},
		()=>{		//5 save

		}
	]
	
	return (xx, bb) => {
		x = xx, b = bb
		switch(b){
			case 1:
			case 2:
				f[p]()
				break
			case 3:
				if(p<2){
					c = 8
					n = [0,0,0,0]
					x.dis = p ? x.all[x.page] : Array.from(x.all[x.all.length-2])
					flash(p ? 0 : 8)
					p = p ? 0 : 1			
				}else if(p==2){
					p = 5
					x.dis = Array.from(x.all[x.all.length-1])
				}else if(p==3){
					p = 2
					;[5,6,7,8].map(i=>set(i, 0))
				}else if(p==4){
					flash()
					p = 3
					;[9,10,11,12].map(i=>set(i, 0))
				}
				break
			case 4:
				if(p==1){
					if(n[0]+n[1]+n[2] == 0 & n[3] == 1){
						c = 0
						p = 2
						;[5,6,7,8].map(i=>set(i, 0))
						Z.menu[0].map((i, j)=>set(j+1, i))				
						flash()
					}				
				}else if(p==2){
					p = 3
					d = (c+1)*5
					Z.menu[d].map((i, j)=>set(j+5, i))	
				}else if(p==3){
					p = 4
					;[9,10,11,12].map(i=>set(i, 1))				
					flash(12)
				}else if(p==5){
					p = 0
					x.dis = x.all[x.page]
				}
		}
	}
})()

Z.met = (()=>{
	
})()

Z.com = (()=>{
	
})()